<!--
 * @Author: your name
 * @Date: 2021-07-28 14:20:21
 * @LastEditTime: 2021-07-28 15:20:05
 * @LastEditors: lmh
 * @Description: 传送门Teleport
-->
<template>
  <div>
    <button @click="handleOpen">弹出一个模态窗口</button>
    <teleport to="body">
      <div v-if="modelOPen" class="modal">
        <div>
          这是一个弹窗
          我的父元素是body
          <button @click="handleClose">关闭</button>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script>
export default {
  data() {
    return {
      modelOPen: false,
    };
  },

  methods: {
    handleOpen() {
      this.modelOPen = true;
    },
    handleClose() {
      this.modelOPen = false;
    },
  },
};
</script>

<style scoped>
.modal {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal div {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: white;
  width: 300px;
  height: 300px;
  padding: 5px;
}
</style>
